<?php
namespace Home\Controller;
use Common\Controller\AdminBaseController;
class SingleController extends AdminBaseController{
    public function index(){
        $id = I('get.id/d');
    	//循环导航栏
    	$list = M('columns')->field('link,columns')->where(['is_nav=1'])->select();
        if(empty($id)){
            //读取单页内容
            $content = M('single')->field('id,title,content')->where(['title'=>'关于我们'])->select();
        }else{
            $content = M('single')->field('id,title,content')->where(['id'=>$id])->select();
        }
        //循环配置
    	$config = M('config')->field('title,value')->select();
        $arr = [];
        foreach ($config as $value) {
           $arr[$value['title']]=$value['value'];
        }
    	//循环右侧导航栏
    	$right = M('single')->field('id,title')->select();
        unset($right[0],$right[6],$right[7],$right[8],$right[9]);
        if($id = 14){
            $this->assign('nav11',14);
        }else{
            $this->assign('nav11',8);
        }
        $collection = M('collection');
        $data = $collection -> field('id,name,litpic') ->limit(5)->order('id desc')-> select();//获取藏品列表数据
        $arr1 = [];//只读取一张图片//读出藏品列表详情
        foreach ($data as $key => $val) {
            $arr1[$key]['id'] =$val['id'];
            $arr1[$key]['name'] =$val['name'];
            $arr1[$key]['pic'] =reset(explode(',',$val['litpic']));
        }
        $this ->assign('arr1',$arr1);
        array_pop($arr1);
        $this ->assign('array',$arr1);
    	$this->assign('list',$list);
        $this->assign('configArr',$arr);
        $this->assign('content',$content[0]);
    	$this->assign('right',$right);
       	$this->display();
    }
    public function pic(){
        $id = I('get.id/d');
        //循环导航栏
        $list = M('columns')->field('link,columns')->where(['is_nav=1'])->select();
        if(empty($id)){
            //读取单页内容
            $content = M('single')->field('id,title,content')->where(['title'=>'关于我们'])->select();
        }else{
            $content = M('single')->field('id,title,content')->where(['id'=>$id])->select();
        }
        $listpic = M('single')->field('img,content')->where(['pid'=>12])->select();
        unset($listpic[0],$listpic[1],$listpic[2],$listpic[3]);
        //循环配置
        $config = M('config')->field('title,value')->select();
        $arr = [];
        foreach ($config as $value) {
           $arr[$value['title']]=$value['value'];
        }
        //循环右侧导航栏
        $right = M('single')->field('id,title')->select();
        unset($right[0],$right[6],$right[7],$right[8],$right[9]);
        $this->assign('list',$list);
        $this->assign('listpic',$listpic);
        $this->assign('configArr',$arr);
        $this->assign('content',$content[0]);
        $this->assign('right',$right);
        $this->display();
    }
}
